package com.example.zhangxin.comevedio.activity.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.zhangxin.comevedio.R;
import com.example.zhangxin.comevedio.activity.MyApplication;
import com.example.zhangxin.comevedio.activity.activity.HomeActivity;

import java.util.List;

/**
 * Created by ZhangXin on 2016/9/13.
 */

public class FlashAdapter extends PagerAdapter {
    private List<Integer> data;
    private Context context;

    public FlashAdapter(List<Integer> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, int position) {
        View view = View.inflate(context, R.layout.flash_vp,null);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_vp);
        imageView.setImageResource(data.get(position));
        if(position==2){
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(new Intent(context,HomeActivity.class));
                    MyApplication.removeActivity((Activity) context);
                    ((Activity) context).finish();
                }
            });
        }
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
